<?php
@session_start();
class Callback extends WebBase{
	public $title='FUN娱乐平台';
	private $vcodeSessionName='ssc_vcode_session_name';
	
	//回调
	public final function synOrderInfo(){
		$server_ip='118.192.163.30';//回调服务器IP
		$ip= $this->ip(false);
		if($server_ip != $ip){
		 	exit('非法IP: '.$ip);
		}
		$Order_no   = $_GET['OrderId'];
		$amount     = isset($_GET['fee']) ? $_GET['fee']/100 : 0;
		$Paychannel = $_GET['Paychannel'];
		$channel    = $_GET['channel'];
		$fdate      = $_GET['fdate'];
		$note = isset($Paychannel) && $Paychannel == 'zx_weixin' ? '微信充值' : '支付宝充值';
		
		$chaxun = "SELECT state FROM ssc_order WHERE order_number = '".$Order_no."'";
		$chaxun2 = "select actionIP from ssc_member_recharge where rechargeid= '".$Order_no."'";
		
		$actionIP=$this->getRow($chaxun2);
		$chaxun3 = "select id from ssc_member_recharge where rechargeid= '".$Order_no."'";
		$id = $this->getRow($chaxun3);

		$chaxun4 = "select uid from ssc_member_recharge where rechargeid= '".$Order_no."'";
		$uid = $this->getRow($chaxun4);
		$chaxun5 = "select coin,username from ssc_members where uid= '".$uid['uid']."'";
		$coin = $this->getRow($chaxun5);
		$chaxun6 = "select value from ssc_params where name='czzs'";
		/* $czzs = $this->getRow($chaxun6);
		if($czzs){
			$amount=$amount*(1+number_format($czzs/100,2,'.',''));
		} */
		$inserts = "insert into ssc_coin_log (uid,type,playedId,coin,userCoin,fcoin,liqType,actionUID,actionTime,actionIP,info,extfield0,extfield1) values ('".$uid['uid']."',0,0,'".$amount."','".$coin['coin']."'+'".$amount."',0,1,0,UNIX_TIMESTAMP(),'".$actionIP['actionIP']."','".$note."','".$id['id']."','".$uid['uid']."')";
		$update1 = "UPDATE ssc_order SET state = 2 WHERE order_number = '".$Order_no."'";
		$update2 = "UPDATE ssc_members SET coin = coin+'".$amount."' WHERE username = '".$coin['username']."'";
		$update3 = "update ssc_member_recharge set state=1,rechargeTime=UNIX_TIMESTAMP(),rechargeAmount='".$amount."',coin='".$coin['coin']."',info='".$note."' where rechargeid='".$Order_no."'";
		
		$jiancha = $this->getRow($chaxun);
		//$actionIP = mysql_result($chaxun2,0);
		if(isset($jiancha) && $jiancha['state']==0){
			if($this->insert($update1)){
				$this->insert($update2);
				$this->insert($update3);
				$this->insert($inserts);
				echo "ok";
			}else{
				echo "数据投递出错";
			}
		}else{
			echo "您已充值，请勿反复刷新,谢谢!";
		}
	}
}